<html>
<head>
    <title>Edit</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="../style/google/Brander.css" />
    <link rel="stylesheet" type="text/css" href="../style/google/btn.css" />
    <link rel="stylesheet" type="text/css" href="../style/google/tab.css" />
    <style type="text/css">
    <!--
    @import "../style/wufoo/public.css";
    @import "../style/wufoo/theme9.css";
    -->
    </style>

    <script type="text/javascript" src="../../../trimpath/template-1.0.38.js"></script>

    <script type="text/javascript">
    var djConfig = {
        isDebug: true,
        //debugAtAllCosts: true
    };
    </script>

    <script type="text/javascript" src="../../../dojo/deploy/dojo.js"></script>
    <script type="text/javascript" src="../../../dojo-lotex/dojo-lotex.js"></script>

    <script type="text/javascript">
    dojo.require("dojo.widget.InlineEditBox");
    dojo.require("dojo.event.topic");
    dojo.require("dojo.widget.PageContainer");
    dojo.require("dojo.widget.TabContainer");
    dojo.require("dojo.event.*");
    dojo.require("rptp.app");
    dojo.require("rptp.rpt");
    dojo.require("lotex.widget.DataTable");
    dojo.require("lotex.Form");
    dojo.require("lotex.table");
    dojo.require("dojo.widget.*");
    dojo.require("dojo.widget.Dialog");
    dojo.require("lotex.widget.Dialog");
    dojo.hostenv.writeIncludes();
//  alert(dojo.uri.moduleUri("lotex.dojo.wiget") + "templates/TabContainer.html");
//  dojo.widget.TabContainer.templateCssPath = dojo.uri.moduleUri("lotex.dojo.wiget");

    </script>

    <script type="text/javascript">
    function populateDatasetTable(definition) {
        var ds = definition.datasets;
        dd(ds);
        for(var i=0; i<ds.length; i++) {
            appendRow(ds[i]);
        }
    };
    function appendRow(dataset) {
    dd(dataset);
        var row=lotex.table.appendRow("rptd.dataset");
        row.setAttribute("rptd.datasetId", dataset["id"]);
        with (row){
            //valign="top";

            var oCell=insertCell(0);
            oCell.className="app listLine";
            oCell.innerHTML= dataset.name;

            var oCell=insertCell(1);
            oCell.className="app listLine listLineMore";
            oCell.innerHTML= dataset.datasource.name;
            var oCell=insertCell(2);
            oCell.className="app listLine listLineMore";
            oCell.innerHTML= dataset.query;
        }
    }
    function getRptId() {
        return dojo.byId("rptd.id").value;
    }

    function preview() {
        var url = rptp.rpt.getDatasetURL(getRptId());
        d(url);
        lotex.widget.DataTable("form.1", [url,"customers.json"]);
        //lotex.widget.DataTable("form.1","http://localhost:8080/rptps3/resources/rptd!data.html");
    }

    function saveHandler(newValue, oldValue) {
        dojo.debug("New Value: " + newValue + " Old Value: " + oldValue);

        if(newValue == "null") {
            alert("更改失败，名称不能为 null 。");
            var editable = dojo.widget.byId("editable");
            var v = editable[editable.mode.toLowerCase()];
            v.value = oldValue;
        } else {
            rptp.asyncSave(
                "Definition",
                {
                    "id":rptp.rpt.getRptIdByUrl(),
                    "name":newValue
                }
            );
        }
    }

    dojo.addOnLoad(function(){
        var editable = dojo.widget.byId("editable");
        editable.submitButton.value="更改";
        editable.cancelButton.value="返回";
        dojo.event.connect(editable, "onSave", "saveHandler");
    });

    function selected(page){
        dojo.debug("page selected " + page.widgetId);
        if ("page4"==page.widgetId) preview();
    }
    dojo.event.topic.subscribe("myPageContainer-selectChild", selected);

    var dlg;
    function init(e) {
        dlg = dojo.widget.byId("datasetDialogContent");
    }
    function getDefinitionName() {
        rptp.asyncGet(
            [
                "Definition",
                {
                    "id":rptp.rpt.getRptIdByUrl()
                },
                ["name"]
            ],
            function(response) {
                if(response.done && response.result) {
                    var name = response.result.name;

                    //dojo.byId("editable").innerText = name;
                    var editable = dojo.widget.byId("editable");
                    editable.setValue(name);

                } else {
                    if(response.message) alert(response.message);
                    else alert("Response not valid JSON!");
                }
            }
        );
    }
    dojo.addOnLoad(init);
    dojo.addOnLoad(getDefinitionName);
</script>
<style type="text/css">
body { font-family : sans-serif; }

.dojoDialog {
    border: 1px solid rgb(51, 51, 51);
    padding: 0pt;
    font-family: arial,sans-serif;
    position: absolute;
    z-index: 6;
    display: block;
    width: 400px;
    height: 350px;
    background-color: White;
}

form {
    margin-bottom : 0;
}

.dlgNotRounded{
    font-family:arial,sans-serif;
    position:absolute;
    padding:0;
    z-index:6;
    border:1px solid #333;
    display:block;
    background-color:White;
}

.dlgBar{
    position:absolute;
    background-color:transparent;
    border-style:none;
    border-width:0;
    cursor:default;
    font-size:16px;
    font-weight:bold;
    vertical-align:middle;
    line-height:30px;
    width: 100%;
    height:30px;
    left:0px;
    top:0px;
    cursor:pointer;
    padding-left: 5px;
}
.dlgClose{
    position:absolute;
    top: 2px;
    height: 22px;
    right: 5px;
    background-color:transparent;
    padding:0;
    vertical-align:middle;
    text-align:right;
    border-style:none;
    border-width:0;
    cursor:pointer;
    color:#00c;
    text-decoration:underline;
    font-weight:normal;
    font-size:13px;
    line-height:30px;
}

.funcsContent{
    font-family:arial,sans-serif;
    font-size:10pt;
    position:absolute;
    text-align:left;
    background-color:#c3deff;
    background-image: none;
    left: 0px;
    top: 30px;
    padding-top: 12px;
    padding-right: 12px;
    padding-bottom: 24px;
    padding-left: 12px;
}
</style>
    <style type="text/css">
<!--
.style1 {
    font-size: 24px;
    font-family: "Courier New", Courier, monospace;
    font-weight: bold;
    text-decoration: none;
}
-->
</style>
</head>
<body>
    <table cellpadding="4" cellspacing="0" width="100%" class="app">
        <tbody>
            <tr>
                <td width="72" style="padding-left: 2px">
                    <a href="#" class="style1" onClick="DoneButtonClicked(this); return false;">RPTP</a></td>
                <td align="right" style="padding-top: 0px">
                    <table cellpadding="0" cellspacing="0" width="100%">
                        <tbody>
                            <tr>
                                <td class="app" align="right">
                                    <strong>Lot </strong>| <a href="#" title="Back to Docs &amp; Spreadsheets" onClick="DoneButtonClicked(this); return false;"
                                        class="app">主页</a> | <a href="/?action=help" class="app" target="_blank">帮助</a>
                                    | <a href="/logout" class="app" target="_top">退出</a>
                                </td>
                                <td class="app" width="4">
                            </tr>
                        </tbody>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    <table cellpadding="4" cellspacing="0" width="100%">
        <tbody>
            <tr>
                <td>
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr valign="bottom">
                            <td nowrap class="docTitle" style="padding-right: 6px">
                                <span id="editable" dojotype="inlineEditBox" title="点击更改名称">新建报表方案 (1)</span></td>
                            <td class="docEditedBy" id="noticeDiv" style="padding-bottom: 1px">
                                创建者：Lot</td>
                        </tr>
                    </table>
                </td>
                <td align="right">
                    <table cellpadding="0" cellspacing="0" border="0">
                        <tr>
                            <td align="right">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tbody>
                                        <tr>
                                            <td class="app">
                                            </td>
                                            <td nowrap style="padding-right: 1px; display: none" id="SaveButtonOff">
                                                <a title="Save changes" class="btn onbtn ButtonDisabled"><b><b><b><span style="font-weight: bold;
                                                    color: aaa">Save</span></b></b></b> </a>
                                            </td>
                                            <td nowrap style="padding-right: 1px;" id="SaveButtonOn">
                                                <a href="#" title="Save changes" onClick="SaveDocContentsWithNotify(null); return false;"
                                                    class="btn onbtn"><b><b><b><strong>预览</strong></b></b></b> </a>
                                            </td>
                                            <td nowrap style="padding-right: 1px">
                                                <a href="#" title="Save changes and close window" id="DoneButton" onClick="DoneButtonClicked(this); return false;"
                                                    class="btn onbtn"><b><b><b>保存</b></b></b> </a>
                                            </td>
                                            <td nowrap>
                                                <a href="#" title="Discard changes to the document" onClick="CancelButtonClicked(this); return false;"
                                                    class="btn onbtn"><b><b><b>删除</b></b></b> </a>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </tbody>
    </table>
    <table class="gwt-panel" width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <td>
                <div id="after2" dojotype="TabController" containerid="myPageContainer" class="controller3">
                </div>
            </td>
        </tr>
        <tr>
            <td style="vertical-align: top; width: 100%; height: 100%" align="left">
                <div id="myPageContainer" dojotype="PageContainer" style="width: 100%; height: 20em;
                    margin: 1em 0 1em 0;">
                    <div id="page1" dojotype="ContentPane" label="数据集">
                        <a href="javascript:dlg.show()">增加数据集</a>
                        <table id="rptd.dataset" width="100%" border="1">
                            <tr>
                                <td>
                                    名称</td>
                                <td>
                                    数据源</td>
                                <td>
                                    查询</td>
                            </tr>
                        </table>
                    </div>
                    <div id="page2" dojotype="ContentPane" label="属性">
                        <table width="100%" border="1">
                            <tr>
                                <td>
                                    属性名</td>
                                <td>
                                    属性值</td>
                            </tr>
                            <tr>
                                <td>
                                    Title</td>
                                <td>
                                    虚拟医院年度综合报表</td>
                            </tr>
                        </table>
                    </div>
                    <div id="page3" dojotype="ContentPane" label="模版">
                        <form name="form1" method="post" action="">
                            <label>
                                模版路径：
                                <select name="select">
                                    <option value="1" selected>综合模版</option>
                                    <option value="2">专用模版</option>
                                    <option value="3">年度报表模版</option>
                                </select>
                            </label>
                            新建模版
                        </form>
                    </div>
                    <div id="page4" dojotype="ContentPane" label="预览">
                        <fieldset>
                            <legend>预览</legend>
                            <div id="form.1"></div>
                        </fieldset>
                    </div>
                </div>
            </div>
            </td>
        </tr>
    </table>
    <div>
    </div>
    <div id="container">
    </div>

    <script type="text/javascript">
    //definitionUri: "http://localhost:8080/rptps3/resources/rptd!edit.html?definitionId=4028807c0f557272010f55c8738f0005",
    dojo.debug("DOJO INSTALL!");

    rptp.app.message("读取报表方案定义……");
    var reportDefinition = lotex.io.bind({
            url: rptp.rpt.getDefinitionURL(),
            error: function(type, data, evt){
                rptp.app.message("报表方案读取失败！请确认数据库是否正常连接，报表ID是否正确");
            },
            load: function(type, data, evt) {
                rptp.app.message("报表方案读取完毕！");
                dd(data);
                populateDatasetTable(data);
            },
            mimetype: "text/json"
        }
    );
    </script>

<!-- 数据集表单 -->
<a dojoType="lotex:dialog" id="datasetDialogContent" toggle="fade" toggleDuration="250"
    executeScripts="true" href="form-dataset.html" bgColor="white" bgOpacity="0.5" title="数据集"></a>
</body>
</html>